let sleep = (time) => new Promise((resolve) => {
    setTimeout(resolve,time)
})

async function changeColor(color,duration) {
    console.log('traffice-light',color);
    await sleep(duration);
}

async function main() {
    while(1){
        await changeColor('red',2000);
        await changeColor('yellow',2000);
        await changeColor('green',2000);
    }
}
main();